package com.spark.tags;

import com.spark.core.SparkContext;
import com.spark.core.XMap;

/**
 * 
 * @version $Id: Box.java v 1.0 2011-3-17 下午10:17:20 IBM Exp $
 * @author <a href="mailto:njq.niu@hand-china.com">vincent</a>
 */
public class Box extends GridLayout {
	
	public static final String TAG_NAME = "box";
	
	private static final String DEFAULT_TH_CLASS = "layout-th";
	public static final String PROPERTITY_LABEL_WIDTH = "labelWidth";
	public static final String PROPERTITY_SHOW_MARGIN = "showMargin";
	
	protected int getLabelWidth(XMap field, XMap view){
		Integer labelWidth = field.getInt(PROPERTITY_LABEL_WIDTH);
		if(labelWidth==null){
			labelWidth = view.getInt(PROPERTITY_LABEL_WIDTH, 75);
		}
		return labelWidth;
	}
	
	protected void beforeBuildCell(StringBuilder sb, SparkContext context, XMap view, XMap field) throws Exception{
		String label = getFieldPrompt(field, context);
//		label = session.getLocalizedPrompt(label);
		int labelWidth = getLabelWidth(field,view);
		if(label!=null) {
//			StringBuilder str = new StringBuilder();
			sb.append("<th class='");
			sb.append(DEFAULT_TH_CLASS);
			sb.append("' ");
			String ps = field.getString(PROPERTITY_PROMPT_STYLE);
			if(ps != null){
				sb.append(" style='");
				sb.append(ps);
				sb.append("' ");
			}
			sb.append("width=").append(labelWidth);
			sb.append("><div>");
			sb.append(label);
			sb.append(":</div></th>");
//			sb.append(str.toString());
		}
	}
}
